var $table;  
var selectionIds = [];  //保存选中ids  
var busRegionField = dataObject.busRegionField;
var singleStatus;
var toolbar = "toolbar_dialog";
var isSelected = true;
$(function () {
	  var columns =[
                       {field: 'state', checkbox: true},
                       {field: 'regionName' , title: busRegionField.regionName, sortName:'region_name' , sortable: true,halign: 'center',align: 'center'},
                       {field: 'regionCode' , title: busRegionField.regionCode, sortName:'region_code' , sortable: true,halign: 'center',align: 'center'},
                       {field: 'parentCode' , title: busRegionField.parentCode, sortName:'parent_code' , sortable: true,halign: 'center',align: 'center'},
                       {field: 'remark' , title: busRegionField.remark, sortName:'remark' , sortable: true,halign: 'center',align: 'center'},
                       {field: 'createTime' , title: busRegionField.createTime, sortName:'create_time' , sortable: true,halign: 'center',align: 'center'},
                       {field: 'userName' , title: busRegionField.createBy, sortName:'create_by' , sortable: true,halign: 'center',align: 'center'},
                       {field: 'status' , title: busRegionField.status, formatter: 'statusFormatter', sortName:'status' , sortable: true,halign: 'center',align: 'center'},
                       {field: 'action', title: pageData.action, formatter: '$table.actionFormatter', events: 'actionEvents', clickToSelect: false, width: 150, halign: 'center', align: 'center'}
                   ];
    $table = new BSTable("table", 'bus/busregion/list', columns,"toolbar",560,'id','id','busregion');
    var queryParams = function(params) {            
         return {
         	       page: params.pageNumber,
         	       limit: params.pageSize,
         	       sidx: params.sortName,
                   order: params.sortOrder,
                   status:vm.search.status,
                   regionName:vm.search.regionName,
                   regionCode:vm.search.regionCode,
                   parentCode:busRegionField.parentCode,
              //查询字段
             };
     };
	$table.setQueryParams(queryParams);
    $table.init();
});


var vm = new Vue({
	el:'#app',
	data:{
		showList: true,
		title: null,
		busRegion: {	
				
		},
		search:{
            regionName:"",
		}
	},
	methods: {
		query: function () {
			defaultActions.query();
		},
		add: function(){
		    vm.busRegion={
		    };
			defaultActions.add(vm);
		},
		update: function (event, id) {
		    defaultActions.update(id, $("#table"),$path+"/bus/busregion/info/", vm, function(r){
	        	vm["busRegion"] = r["busRegion"];
	        });
		},
		saveOrUpdate: function (event) {
		    $('#defaultForm').bootstrapValidator('validate');
			if($('#defaultForm').data('bootstrapValidator').isValid()){
				 var url = vm.busRegion.id == null || vm.busRegion.id == ''? $path+"/bus/busregion/save" : $path+"/bus/busregion/update";
				 defaultActions.saveOrUpdate(url ,vm, $("#defaultForm"),"busRegion",event);
			}
		},
		del: function (event, id) {
		    defaultActions.del(id, $path+"/bus/busregion/delete", $("#table") ) ;
		},
		audit:function(status){
			defaultActions.audit(status , $path+"/bus/busregion/audit?status="+status, vm);
		},
		reload: function (event) {
		    defaultActions.reload($("#table"),$("#defaultForm"),vm,"busRegion"); 
		},
		detail: function (event, id) {
			defaultActions.detail(vm, id, event);
		},
	}
});

/*表单校验 start*/
$('#defaultForm').bootstrapValidator({
    feedbackIcons: vail.feedbackIcons(),
    fields: {
               regionName: vail.REPEATREGEX("区域名称",busRegionField.regionName,"25",$path+"/bus/busregion/checkExist","busRegion","id","regionName","region_name",/^[\S]*$/,"不能有空格"),
               regionCode: vail.REPEATREGEX("区域编码",busRegionField.regionCode,"25",$path+"/bus/busregion/checkExist","busRegion","id","regionCode","region_code",/^[A-Za-z0-9]+$/,"不能有中文和特殊符号"),
               remark: vail.LIMITLENGTH("备注",busRegionField.remark,1,30),
    }
});
/*表单校验 end*/
